#include "mcommon.h"
#include "fileio/fileio.h"
#include "debug/logger.h"

#include <cstring>

namespace renderit
{
	namespace messiah
	{
		/*
		const char * GResourceDirString[EResourceDir_End] = {
			"Animation",
			"Character",
			"Effect",
			"Material",
			"Mesh",
			"Misc",
			"Model",
			"Physics",
			"Skeleton",
			"Sound",
			"Terrain",
			"Texture"
		};

		const char * GResourceTypeString[EResourceType_End] = {
			"Animation",			// EResourceType_Animation
			"CollisionShape",		// EResourceType_CollisionShape
			"Material",				// EResourceType_Material
			"Mesh",					// EResourceType_Mesh
			"Model",				// EResourceType_Model
			"NavigateMap",			// EResourceType_NavigateMap
			"ParticleSystem",		// EResourceType_ParticleSystem
			"PointCloud",			// EResourceType_PointCloud
			"SkinSkeleton",			// EResourceType_SkinSkeleton
			"Terrain",				// EResourceType_Terrain
			"Texture",				// EResourceType_Texture
			"VisibilityCube"		// EResourceType_VisibilityCube
		};

		static EResourceDir GResourceTypeToDir[EResourceType_End] = {
			EResourceDir_Animation,	// EResourceType_Animation
			EResourceDir_Physics,	// EResourceType_CollisionShape
			EResourceDir_Material,	// EResourceType_Material
			EResourceDir_Mesh,		// EResourceType_Mesh
			EResourceDir_Model,		// EResourceType_Model
			EResourceDir_End,		// EResourceType_NavigateMap
			EResourceDir_End,		// EResourceType_ParticleSystem
			EResourceDir_End,		// EResourceType_PointCloud
			EResourceDir_End,		// EResourceType_SkinSkeleton
			EResourceDir_Terrain,	// EResourceType_Terrain
			EResourceDir_Texture,	// EResourceType_Texture
			EResourceDir_End		// EResourceType_VisibilityCube
		};*/

		struct ResourceType
		{
			EResourceType type;
			std::string name;
			std::string dirname;
		};

		static ResourceType iGResourceType[EResourceType_End] = 
		{
			{ EResourceType_Animation,		"Animation",		"Animation"			},
			{ EResourceType_CollisionShape,	"CollisionShape",	"Physics"			},
			{ EResourceType_Material,		"Material",			"Material"			},
			{ EResourceType_Mesh,			"Mesh",				"Mesh"				},
			{ EResourceType_Model,			"Model",			"Model"				},
			{ EResourceType_NavigateMap,	"NavigateMap",		"Navigate"			},
			{ EResourceType_ParticleSystem,	"ParticleSystem",	"Effect"			},
			{ EResourceType_PointCloud,		"PointCloud",		"PointCloud"		},
			{ EResourceType_SkinSkeleton,	"SkinSkeleton",		"Skeleton"			},
			{ EResourceType_Terrain,		"Terrain",			"Terrain"			},
			{ EResourceType_Texture,		"Texture",			"Texture"			},
			{ EResourceType_VisibilityCube,	"VisibilityCube",	"VisibilityCube"	}
		};

		EResourceType GResourceTypeFromString(const std::string& type_name)
		{
			for (int i = 0; i < EResourceType_End; ++i)
			{
				if (iGResourceType[i].name == type_name)
				{
					return (EResourceType)i;
				}
			}
			logger::warn("Unknown Resource Type:%s", type_name);
			return EResourceType_End;
		}

		const std::string& GResourceTypeString(EResourceType t)
		{
			if (t < EResourceType_End)
			{
				return iGResourceType[t].name;
			}
			logger::warn("Unknown Resource Type:%d", t);
			return "";
		}

		const std::string& GResourceDirFromType(EResourceType t)
		{
			if (t < EResourceType_End)
			{
				return iGResourceType[t].dirname;
			}
			logger::warn("Unknown Resource Type:%d When Fetch Dirname!", t);
			return "";
		}

		const std::string& GResourceDirFromType(const std::string& type_name)
		{
			EResourceType t = GResourceTypeFromString(type_name);
			return GResourceDirFromType(t);
		}
	}
}